/*
 * @brief :   
 * @date :  2022-02-xx
 * @version : v1.0.0
 * @copyright(c) 2020 : OptoMedic company Co.,Ltd. All rights reserved
 * @Change Logs:   
 * @date         author         notes:  
 */
#include "locker_rtthread.h"
#include "rtthread.h"


static int rtthread_lock_func(locker_t *lk)  
{
    rt_mutex_t *mutex = (rt_mutex_t *)lk->private_data;
    return  rt_mutex_take(mutex, RT_WAITING_FOREVER);;
}

static int rtthread_unlock_func(locker_t *lk)  
{
    rt_mutex_t *mutex = (rt_mutex_t *)lk->private_data;
    return  rt_mutex_release(mutex);;
}   

static int rtthread_destroy_func(locker_t *lk)  
{
    rt_mutex_t *mutex = (rt_mutex_t *)lk->private_data;
    return  rt_mutex_delete(mutex);
}

locker_t *locker_rtthread_create(char *name)
{
    locker_t *thiz = (locker_t *) malloc(sizeof(locker_t));
    if (thiz == NULL) return NULL;

    thiz->private_data = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
    if (thiz->private_data == NULL) return NULL;

    thiz->lock = rtthread_lock_func;
    thiz->unlock = rtthread_unlock_func
    thiz->destroy = rtthread_destroy_func;

    rtthread_mutex_init((rt_mutex_t *)thiz->private_data);
}